import Vue from 'vue'
import Router from 'vue-router'

// import Home from '@/components/Home'
// import Item from '@/components/Item';
// import Score from '@/components/Score';

Vue.use(Router)
//懒加载路由: 当前匹配到哪一条路由时才去加载相应的路由组件
//异步组件: 按需加载组件
//代码分割:  所有文件--->app.js

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      // component: require('../components/Home').default

      // component:function(resolve,reject){
      //     //当需要注册组件时才调用
      //     //即当前浏览器的url的pathname匹配当前的path值时，该回调函数才执行
      //     require.ensure([],function(){
      //        resolve(require('../components/Home'));
      //     },'myAbc')
      // },

      // component:r=>require.ensure([],()=>r(require('../components/Home')),'myAbc'),

      //webpack是2.4以上，使用ES6中的import()方法自动添加代码分割点
      component:()=>import(/* webpackChunkName: "myAbc" */ '../components/Home')
    },
    {
      path: '/item/:id',
      name: 'Item',
      // component: function(resolve,reject){
      //     //即当前浏览器的url的pathname匹配当前的path值时，该回调函数才执行
      //     require.ensure([],function(){
      //       resolve(require('../components/Item'));
      //     },'myAbc')
      // }
      component:()=>import(/* webpackChunkName: "myAbc" */ '../components/Item')
    },
    {
      path: '/score',
      name: 'Score',
      // component: function(resolve){
      //   require.ensure([],function(){
      //     resolve(require('../components/Score'));
      //   })
      // }
      component:()=>import('../components/Score')
    }
  ]
})
